﻿#region License

// Copyright © 2004 - 2010 All Right Reserved, Derek Goslin
// 
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
// 
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license
//     conditions and limitations in section 3, each contributor grants you a non-exclusive,
//     worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative 
//     works of its contribution, and distribute its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations
//     in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its
//     licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of
//     its contribution in the software or derivative works of the contribution in the software.
// 
// 3. Conditions and Limitations
// (A) Reciprocal Grants- For any file you distribute that contains code from the software (in source code or binary format), 
//     you must provide recipients the source code to that file along with a copy of this license, which license will govern that file. 
//     You may license other files that are entirely your own work and do not contain code from the software under any terms you choose.
// (B) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (C) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
//     your patent license from such contributor to the software ends automatically.
// (D) If you distribute any portion of the software, you must retain all copyright, patent, trademark,
//     and attribution notices that are present in the software.
// (E) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy 
//     of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do 
//     so under a license that complies with this license.
// (F) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions.
//    You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your
//    local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

#endregion

using System;

namespace DnEcuDiag.Conversion
{
    public class M2103Conversion : IsoConvertor, IConvertor
    {
        #region IConvertor Members

        public float Convert(int conversionId, byte[] rawData)
        {
            float result = 0;
            UInt32 rawValue = ConvertByteArray(rawData);

            switch (conversionId)
            {
                case 24:
                    result = rawValue * 0.0705f;
                    break;
                case 44:
                    result = rawValue;
                    break;
                case 101:
                    result = CalculateRpm(rawData);
                    break;
                case 102:
                    result = rawValue*10f;
                    break;
                case 103:
                    result = M2104TempTableRam[rawValue];
                    break;
                case 104:
                    result = M2104TempTableRam[rawValue];
                    break;
                case 105:
                    result = rawValue*96/230.4f;
                    break;
                case 106:
                    result = rawValue*1.6f;
                    break;
                case 107:
                    result = rawValue*0.2f;
                    break;
                case 108:
                    result = 78 - (rawValue*0.75f);
                    break;
                case 109:
                    result = rawData[0]*0.384f + rawData[1]/255f;
                    break;
                case 110:
                    result = rawValue/255f;
                    break;
                case 111:
                    result = rawValue*96/230.4f;
                    break;
                case 112:
                    result = rawValue*0.05f;
                    break;
                case 113:
                    result = rawValue*0.20f;
                    break;
                case 114:
                    result = rawValue*5/255f;
                    break;
                case 115:
                    result = rawValue*0.0705f;
                    break;
                case 116:
                    result = rawValue;
                    break;
                case 117:
                    result = (rawValue*1.25f)/255;
                    break;
                case 118:
                    result = (rawData[0] - 0x80)*0.8f;
                    break;
                case 119:
                    result = (rawData[0] - 0x80)*2f;
                    break;
                case 120:
                    result = rawValue*10;
                    break;
                case 121:
                    result = rawValue*10;
                    break;
                case 122:
                    result = rawValue*0.39f;
                    break;
                case 123:
                    result = rawValue*96/230.4f;
                    break;
                case 124:
                    result = rawValue/14.68f;
                    break;
                case 125:
                    result = rawValue*5f/255;
                    break;
                case 126:
                    result = M2104TempTableAdc[rawValue];
                    break;
                case 127:
                    result = rawValue*5f/255;
                    break;
                case 128:
                    result = M2104TempTableAdc[rawValue];
                    break;
                case 129:
                    result = rawValue*5000f/255;
                    break;
                case 130:
                    result = rawValue*1250f/255;
                    break;
                case 131:
                    result = rawValue*5f/255;
                    break;
                case 132:
                    result = rawValue*5f/255;
                    break;
                case 133:
                    result = rawValue/14.68f;
                    break;
            }

            return result;
        }

        #endregion
    }
}